<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小黑的书架-2</title>
</head>

<body>
    <div id="app">
        <h3>小黑的书架</h3>
        <ul>
            <!-- 渲染页面 -->
            <li v-for="e in arr" :key="e.id">
                <span>{{e.name}}</span>
                <span>{{e.author}}</span>
                <!-- 设置自定义属性获取id -->
                <button v-on:click="del($event)" :data-id="e.id">删除</button>
            </li>
        </ul>
    </div>
    <script src="vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                arr: [
                    { id: 1, name: '《红楼梦》', author: '曹雪芹' },
                    { id: 2, name: '《西游记》', author: '吴承恩' },
                    { id: 3, name: '《水浒传》', author: '施耐庵' },
                    { id: 4, name: '《三国演义》', author: '罗贯中' }
                ]
            },
            methods: {
                del(e) {
                    let id = e.target.dataset.id
                    // 通过自定义属性获取到id 进行判断
                    this.arr = this.arr.filter(e => id != e.id)
                }
            }
        })
    </script>
</body>

</html>